package com.zyh.work2

object CaoLei {
  def main(args: Array[String]): Unit = {
    //调用父类的无参构造
    var zi = new Zi(1)
    zi.name = "开始"
    zi.age = 22
    zi.show()

    //调用父类的有参构造
    var zi1 = new Zi1()
    zi1.name = "开始"
    zi1.age = 22
    zi1.show()
  }
}
class Fu{
  println("父类主构造器")
  var name:String = _
  var age:Int = _
  def this(name:String,age:Int) = {
    this
    this.name=name
    this.age=age
    println("父类辅助构造器")
  }
}
class Zi(var gender:Int) extends Fu{
  println("子类主构造器")
  def this() = {
    this(0)
    println("子类的辅助构造器")
  }
  def show(): Unit ={
    println(s"name = $name,age = $age,gender = ${gender}")
  }
}

class Zi1(name:String,age:Int,gender:Int) extends Fu(name:String,age:Int){
  println("子类的主构造器")
  def this() = {
    this("wangmign",10,1)
    println("子类的辅助构造器")
  }
  def show(): Unit ={
    println(s"name = $name,age = $age,gender = ${gender}")
  }
}